package com.skcc.cop.mrtaxi.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.skcc.cop.mrtaxi.R;


public class TitleBar3 extends LinearLayout implements View.OnClickListener {
  // ===========================================================
    // Constants
    // ===========================================================
    
    private static final String TAG = TitleBar3.class.getSimpleName();
    
    private final static String MENU = "menu";
    private final static String MOVE_LIST = "move_list";

    // ===========================================================
    // Fields
    // ===========================================================

    public OnTitleBarEventListener3 titlebarEventListener;
    
    private TextView title_textview;
    private ImageView menu_imageview;
    private ImageView move_list_imageview;
    
    private Context context;
    
    /**
     * 생성자
     * 
     * @param context
     * @param attrs
     */
    public TitleBar3(Context context, AttributeSet attrs) {
        super(context, attrs);
        
        this.context = context;
        
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View titlebar = inflater.inflate(R.layout.view_titlebar3, this, true);
        
        title_textview = (TextView) titlebar.findViewById(R.id.titlebar_title_textview);
        
        menu_imageview = (ImageView) titlebar.findViewById(R.id.titlebar_menu_imageview);
        menu_imageview.setTag(MENU);
        menu_imageview.setOnClickListener(this);
        
        move_list_imageview = (ImageView) titlebar.findViewById(R.id.titlebar_move_list_imageview);
        move_list_imageview.setTag(MOVE_LIST);
        move_list_imageview.setOnClickListener(this);
        
    }
    
    public void setTitle(String titleStr) {
     title_textview.setText(titleStr);
    }
    
    public void setTitle(int resId) {
     String title = this.context.getResources().getString(resId);
     title_textview.setText(title);
    }
    
    public void showMenu() {
     menu_imageview.setVisibility(View.VISIBLE);
    }
    
    public void hideMenu() {
     menu_imageview.setVisibility(View.GONE);
    }
    
    public void showMoveList() {
     move_list_imageview.setVisibility(View.VISIBLE);
    }
    
    public void hideMoveList() {
     move_list_imageview.setVisibility(View.GONE);
    }
    
    /**
     * @param listener
     */
    public void setEventListener(OnTitleBarEventListener3 listener)
    {
     titlebarEventListener = listener;
    }
    
    /**
     * callback 을 등록취소하는 메소드
     */
    public void removeEventListener()
    {
     titlebarEventListener = null;
    }
    
    public void onClick(View v)
    {
        if (v.getTag().equals(MENU))
        {
         titlebarEventListener.onMenuClicked();
        } else if (v.getTag().equals(MOVE_LIST))
        {
         titlebarEventListener.onMoveListClicked();
        } 
    }
    
    
    public interface OnTitleBarEventListener3 {
     
        public void onMenuClicked();
        public void onMoveListClicked();
       
    }
} 
